//
import 'package:flutter/material.dart';
import 'package:hktk_app/ienum/my/rank_type_enum.dart';
import 'package:hktk_app/ienum/subject/collection_type_enum.dart';
import 'package:hktk_app/model/my/chaper_tree_model.dart';
import 'package:hktk_app/pages/question/collection_question_page.dart';
import 'package:hktk_app/util/font_util.dart';

import 'package:hktk_app/util/view_util.dart';

/// 我的错题/收藏底层显示组件
class ViewChapterShowWidget extends StatelessWidget {
  /// 内容显示
  final ChapterTreeModel chapterModel;

  /// 是错题还是收藏
  final RankTypeEnum rankType;

  const ViewChapterShowWidget({
    super.key,
    required this.chapterModel,
    required this.rankType,
  });

  @override
  Widget build(BuildContext context) {
    debugPrint("viewChapterShowWidget 组件 build 方法执行 ===> ");
    debugPrint("");
    return GestureDetector(
      onTap: () {
        _onTapFunDj(context);
      },
      child: SizedBox(
        height: 48,
        child: Row(
          children: [
            Expanded(child: _titleItem()),
            _errItem(),
          ],
        ),
      ),
    );
  }

  /// 标题组件显示
  _titleItem() {
    return Text(
      chapterModel.name!,
      maxLines: 1,
      overflow: TextOverflow.ellipsis,
      style: FontUtil.fontGrey2(28),
    );
  }

  /// 错题数显示
  _errItem() {
    int? num =
    rankType == RankTypeEnum.error ? chapterModel.ec : chapterModel.cc;
    return Text(
      "${num ?? 0} 道",
      style: rankType == RankTypeEnum.error
          ? FontUtil.fontRed2(28)
          : FontUtil.fontBlue1(28),
    );
  }

  /// 点击方法
  void _onTapFunDj(BuildContext context) {
    Navigator.pushNamed(context, "/collection",arguments: {
      "collectId": chapterModel.id!,
      "collectionType": CollectionTypeEnum.chapter,
      "type": rankType,
    });

  }
}
